
package com.hyst.tool;


/**
 * @Description:字段类型转换器 驼峰
 * @Date：2017年6月20日
 * @author： DongY
 * @version ：1.0
 * 	  1.[2017年6月20日]CreatBy：dy
 */

public class HumpConversion implements TypeCnversion{
	/**
	 * 下划线转驼峰
	 */
	@Override
	public String cast(String fiedName) {
		if (StringUtil.isEmpty(fiedName)) {
			return "";
		}
		String [] strings=fiedName.split("_");
		String str=strings[0];
		for(int i=1;i<strings.length;i++){
			str+=StringUtil.headToUpper(strings[i]);
		}
		return str;
	}

	@Override
	public String toJavaType(String sqlType) {
		String type = "";

		if (sqlType.indexOf('(')>0) {
			sqlType = sqlType.substring(0, sqlType.indexOf('(')).toUpperCase();
		}

		if (sqlType.indexOf("INT") > 0) {
			type = "int";
		} else if (sqlType.indexOf("BLOB") > 0) {
			type = "BLOB";
		}

		switch (sqlType.toUpperCase()) {
			case "VARCHAR":
			case "CHAR":
			case "TEXT":
				type = "String";
				break;
			case "TINYINT":
			case "SMALLINT":
			case "MEDIUMINT":
			case "INT":
			case "DECIMAL":
			case "BOOLEAN":// ֵΪ0,1
				type = "int";
				break;
			case "MEDIUMBLOB":
			case "VARBINARY":
			case "BINARY":
			case "BIT":
				type = "byte[]";
				break;
			case "FLOAT":
				type = "float";
				break;
			case "DOUBLE":
				type = "double";
				break;
			case "DATE":
			case "DATETIME":
			case "TIMESTAMP":
			case "TIME":
	
				type = "java.util.Date";
				break;
		}
		return type;
	}

}
